import { doAjax,doAjaxWithFile } from "utils"

const state = {
  base: {
    loading: false,
    pagination: {}
  },
  data: {
    list: []
  }
}

const actions = {
  getData({ commit }, params) {
    commit('UPDATE_LOADING', true)
    return doAjax({
      url: URLConfig('messageTemplateList'),
      data: params,
      sucCallback(data) {
        commit('UPDATE_LIST', data.list)
        commit('UPDATE_PAGINATION', data.page)
        commit('UPDATE_LOADING', false)
      },
      failCallback(data) {
        commit('UPDATE_LOADING', false)
      }
    })
  },
  sendMsg({ commit }, params) {
    return doAjaxWithFile({
      url: URLConfig('messageTemplateSend'),
      method: 'post',
      data: params,
      sucCallback(data) {

      },
      failCallback(data) {
      }
    })
  },
  deleteMsg({ commit }, params) {
    return doAjax({
      url: URLConfig('messageTemplateDelete'),
      data: params,
      sucCallback(data) {
        
      },
      failCallback(data) {
      }
    })
  },
  saveMsg({ commit }, params) {
    return doAjax({
      url: URLConfig('messageTemplateSave'),
      data: params,
      method: 'post',
      sucCallback(data) {
        
      },
      failCallback(data) {
      }
    })
  }
}

const mutations = {
  UPDATE_LIST(state, data) {
    state.data.list = data
  },
  UPDATE_PAGINATION(state, data) {
    state.base.pagination = data
  },
  UPDATE_LOADING(state, data) {
    state.base.loading = data
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
